#include <gtk/gtk.h>
#include <stdio.h>
void haha(GtkButton *button,gpointer user_data);
void xixi(GtkButton *button,gpointer user_data);
void hehe(GtkButton *button,gpointer user_data);

GtkWidget* label_empty;
GtkWidget* entry;
int main(int argc, char  *argv[])
{
    //-------------------------------------------------------------------------------
    //窗口
    gtk_init(&argc,&argv);
    GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title((GtkWindow*)window,"IceBear");
    gtk_widget_set_size_request(window,410,190);
    gtk_window_set_resizable((GtkWindow*)window,FALSE);
    gtk_window_set_position((GtkWindow*)window,GTK_WIN_POS_CENTER);
    //-------------------------------------------------------------------------------
    //组件
    //按钮
    //GtkWidget* button_sure = gtk_button_new();
    GtkWidget* button_sure = gtk_button_new_with_label("Sure");
    GtkWidget* button_cancel = gtk_button_new_with_label("Cancel");
    GtkWidget* button_browse = gtk_button_new_with_label("Browse");
    //标签
    GtkWidget* label_title = gtk_label_new("label one");
    GtkWidget* label_open = gtk_label_new("label two");
    label_empty = gtk_label_new("");
    //行编辑
    entry= gtk_entry_new();
    //-------------------------------------------------------------------------------
    //布局

    //垂直布局
    GtkWidget* vbox = gtk_vbox_new(TRUE, 5);
    //水平布局
    GtkWidget* hbox_mid = gtk_hbox_new(TRUE, 0);
    GtkWidget* hbox_buttom = gtk_hbox_new(TRUE, 5);

    gtk_container_add(GTK_CONTAINER(hbox_mid),label_open);
    gtk_container_add(GTK_CONTAINER(hbox_mid),entry);

    //加入布局
    gtk_container_add(GTK_CONTAINER(hbox_buttom),label_empty);
    gtk_container_add(GTK_CONTAINER(hbox_buttom),button_sure);
    gtk_container_add(GTK_CONTAINER(hbox_buttom),button_cancel);
    gtk_container_add(GTK_CONTAINER(hbox_buttom),button_browse);

    gtk_container_add(GTK_CONTAINER(vbox),label_title);
    gtk_container_add(GTK_CONTAINER(vbox),hbox_mid);
    gtk_container_add(GTK_CONTAINER(vbox),hbox_buttom);
    //添加到window		//容器				//控件
    //gtk_container_add(GTK_CONTAINER(window),button_sure);
    //不能重复田间同一个控件
    gtk_container_add(GTK_CONTAINER(window),vbox);

//-------------------------------------------------------------------------------
    //显示所有控件区别于gtk_widget_show(window);
    gtk_widget_show_all(window);
    g_signal_connect(window,"destroy",G_CALLBACK(gtk_main_quit),NULL);
    g_signal_connect(button_sure,"pressed",G_CALLBACK(haha),"teng");
    g_signal_connect(button_cancel,"pressed",G_CALLBACK(xixi),NULL);
    g_signal_connect(button_browse,"pressed",G_CALLBACK(hehe),NULL);
    g_signal_connect(entry,"activate",G_CALLBACK(haha),"NULL");
    //-------------------------------------------------------------------------------
    gtk_main();//等待信号连接
    return 0;
}

 //-------------------------------------------------------------------------------
//回调函数
void haha(GtkButton *button,gpointer user_data)
{
    //1、信号连接直接打印
    printf("hahahahahaha\n");
    //2、打印传递过来的参数
    printf("%s\n", (char *)user_data);
}
void xixi(GtkButton *button,gpointer user_data)
{
    const char *text = gtk_button_get_label(GTK_BUTTON(button));
    printf("%s\n",text );
    const char *text1 = gtk_label_get_label(GTK_LABEL(label_empty));
    printf("%s\n",text1 );
    const char *text2 = gtk_entry_get_text(GTK_ENTRY(entry));
    printf("%s\n",text2 );
}
void hehe(GtkButton *button,gpointer user_data)
{
    gtk_label_set_text(GTK_LABEL(label_empty),"hehe");
    gtk_entry_set_text(GTK_ENTRY(entry),"hello");
}

	//gcc	*.c 	-o	demo
	//编译gdk需要加上条件 `pkg-config --cflags --libs gtk+-2.0`
	/* code */